# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pycairo
pkgbase=mingw-w64-python3-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-python3-cairo"
pkgver=1.10.0
pkgrel=5
pkgdesc="Python2 bindings for the cairo graphics library (mingw-w64)"
url="http://www.cairographics.org/pycairo"
arch=('any')
license=('LGPL' 'MPL')
depends=("${MINGW_PACKAGE_PREFIX}-python3" "${MINGW_PACKAGE_PREFIX}-cairo")
makedepends=("python3")
source=(http://cairographics.org/releases/${_realname}-${pkgver}.tar.bz2
        context.patch
        pycairo-1.10.0-waf-python3.4.tar.bz2)
sha256sums=('9aa4078e7eb5be583aeabbe8d87172797717f95e8c4338f0d4a17b683a7253be'
            '4ce2b07430e0151d93c89a3f20eca1341e0693adc7345951df8ce841ad6d4fa6'
            '65822022d1f42f9128aba725d74f625e11899a2319765917cc7357c080f09aba')

prepare() {
  cd "${srcdir}/pycairo-${pkgver}"
  patch -p1 -i ${srcdir}/context.patch
  patch -p1 -i ${srcdir}/pycairo-1.10.0-waf-python3.4.patch
  sed -i 's:bin/env python:bin/env python3:' waf
}

build() {
  cd "${srcdir}/pycairo-${pkgver}"

  /usr/bin/python3 ./waf --version || true
  pushd .waf3-*
  #patch -p0 -i ${srcdir}/waflib.patch
  #rm -f waflib/*.pyc
  popd

  CFLAGS+=" -I${MINGW_PREFIX}/include/python3.4m"
  #CXXFLAGS+=" -I${MINGW_PREFIX}/include/python3.4m"
  export PYTHON=${MINGW_PREFIX}/bin/python3
  /usr/bin/python3 ./waf --help
  /usr/bin/python3 ./waf configure --prefix=${MINGW_PREFIX}
  /usr/bin/python3 ./waf build
}

package() {
  cd "${srcdir}/pycairo-${pkgver}"
  /usr/bin/python3 ./waf install --destdir="${pkgdir}"

  rm -rf ${pkgdir}${MINGW_PREFIX}/lib
  mv ${pkgdir}${MINGW_PREFIX}/bin ${pkgdir}${MINGW_PREFIX}/lib
}
